home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ccdl150l.zip / IO / PUTGET.C < prev    next >
C/C++ Source or Header  |  1997-04-08  |  1KB  |  67 lines

  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <libp.h>
  4.  
  5. int _baseputc(int c, FILE *stream)
  6. {
  7.     unsigned char rv = (unsigned char) c;
  8.     if (!(stream->flags & _F_BIN) && c == '\n')
  9.         if (_baseputc('\r',stream) == EOF)
  10.             return EOF;
  11.     if (stream->bsize) {
  12.         if (_writebuf(stream)) {
  13.             stream->flags |= _F_ERR;
  14.             return EOF;
  15.         }
  16.         stream->flags |= _F_OUT;
  17.         *stream->curp++ = (char)c;
  18.         stream->level++;
  19.         if (c == '\n' && (stream->flags & _F_LBUF))
  20.             fflush(stream);
  21.         return c;
  22.     }
  23.     else {
  24.         if (_ll_write(stream->fd,&rv,1)) {
  25.             stream->flags |= _F_ERR;
  26.             return EOF;
  27.         }
  28.     }
  29.     return c;
  30. }
  31. int _basegetc(FILE *stream)
  32. {
  33.     unsigned char rv;
  34.     if (stream->bsize) {
  35.         if (_readbuf(stream))
  36.             return EOF;
  37.         if (!(stream->flags & _F_BIN)) {
  38.             if (*stream->curp == '\r') {
  39.                 stream->flags |= _F_SKIPLF;
  40.                 stream->level--;
  41.                 stream->curp++;
  42.                 return('\n');
  43.             }
  44.             else 
  45.                 if (*stream->curp == '\n' && stream->flags & _F_SKIPLF) {
  46.                     stream->level--;
  47.                     stream->curp++;
  48.                     stream->flags &= ~_F_SKIPLF;
  49.                     return(_basegetc(stream));
  50.                 }
  51.         }
  52.         stream->level--;
  53.         return(*stream->curp++);
  54.     }
  55.     else if (stream->hold) {
  56.         rv = stream->hold;
  57.         stream->hold = 0;
  58.     }
  59.     else {
  60.         if (!_ll_read(stream->fd,&rv,1)) {
  61.             stream->flags |= _F_EOF;
  62.             return EOF;
  63.         }
  64.     }
  65.     return(rv);
  66. }
  67.